package com.shen.yun.controller;

        import com.fasterxml.jackson.core.JsonProcessingException;
        import com.fasterxml.jackson.databind.ObjectMapper;
        import com.shen.yun.util.ChatWebSocket;
        import org.springframework.stereotype.Controller;
        import org.springframework.ui.Model;
        import org.springframework.web.bind.annotation.RequestMapping;

        import java.util.HashMap;
        import java.util.Map;

@Controller
public class RoomController {
    @RequestMapping("/room")
    public String game(Model model) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String , Integer> rmMap = new HashMap<>();
        for (String rmId : ChatWebSocket.roomMap.keySet()){
            rmMap.put(rmId,ChatWebSocket.roomMap.get(rmId).getLeftPlayerNum());
        }

        //roomId：几人场
        model.addAttribute("roomMap", objectMapper.writeValueAsString(rmMap));
        return "room";
    }

    @RequestMapping("/tst")
    public String tst(Model model) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String , Integer> rmMap = new HashMap<>();
        for (String rmId : ChatWebSocket.roomMap.keySet()){
            rmMap.put(rmId,ChatWebSocket.roomMap.get(rmId).getLeftPlayerNum());
        }

        //roomId：几人场
        model.addAttribute("roomMap", objectMapper.writeValueAsString(rmMap));
        //roomId：几人场
        return "tst";
    }
}
